Skip to content

fix(tui): prevent crash when task references missing child session#26944

Open
shalin-dev wants to merge 6 commits into
anomalyco:devfrom
shalin-dev:fix/tui-crash-missing-child-session
Open

fix(tui): prevent crash when task references missing child session#26944
shalin-dev wants to merge 6 commits into
anomalyco:devfrom
shalin-dev:fix/tui-crash-missing-child-session

Conversation

@shalin-dev

@shalin-dev shalin-dev commented May 11, 2026

Copy link
Copy Markdown

Issue for this PR

Closes #26871

Type of change

  • Bug fix
  • New feature
  • Refactor / code improvement
  • Documentation

What does this PR do?

The Task component in the session TUI route fires sync.session.sync(sessionId) as a fire-and-forget promise (void ...) without .catch(). When the child session referenced by a task tool part has been deleted or doesn't exist, the SDK call throws and the unhandled promise rejection crashes the TUI process.

Two changes:

  1. Added .catch(() => {}) to the void sync.session.sync() call in onMount. This is a fire-and-forget sync with no user-facing error to show, so swallowing the rejection is appropriate. The sync was only needed to populate local state for a session that no longer exists.

  2. Added a childExists memo that checks sync.data.session for the child session ID, and guards the onClick navigation with it. Without this, clicking a task row for a missing session would navigate to a dead-end session view.

How did you verify your code works?

  • Wrote a regression test at test/cli/tui/task-missing-session.test.ts confirming .catch() prevents unhandled rejection on missing sessions
  • bun run typecheck passes across all 14 packages
  • bun test test/cli/tui/task-missing-session.test.ts - 1 pass, 0 fail

Screenshots / recordings

N/A - TUI behavior change, no visual diff.

Checklist

  • I have tested my changes locally
  • I have not included unrelated changes in this PR

The Task component's onMount fires sync.session.sync(sessionId) as a
fire-and-forget promise without .catch(). When the child session has
been deleted or doesn't exist, the unhandled rejection crashes the TUI.

Guard the onClick navigation with a childExists memo to prevent
navigating to a dead-end session view for missing sessions.

Closes anomalyco#26871
@github-actions github-actions Bot added needs:compliance This means the issue will auto-close after 2 hours. and removed needs:compliance This means the issue will auto-close after 2 hours. labels May 11, 2026
@github-actions

Copy link
Copy Markdown
Contributor

Thanks for updating your PR! It now meets our contributing guidelines. 👍

@kommander

Copy link
Copy Markdown
Collaborator
  • childExists only checks local session-list cache, not whether the child sync succeeded.
  • If the child is stale in sync.data.session but session.get now returns 404, sync fails and is swallowed, yet childExists() can remain true, so clicking can still navigate to a missing child session.
  • The added test only proves that a synthetic rejected promise with .catch(() => {}) does not emit unhandledRejection. It does not mount Task, call sync.session.sync, verify stale rendering, or verify navigation behavior.
  • It also catches all errors and still leaves a clickable affordance via an always-present onClick.

…issing sessions

- Replace childExists memo (checked stale cache) with sessionMissing signal
  that tracks actual sync failure outcome
- Record error in .catch() instead of swallowing it silently
- Conditionally pass onClick (undefined when session missing) so InlineTool
  removes click affordance entirely — no misleading clickable-but-dead state
- Remove synthetic test — no TUI testing infrastructure exists in codebase
@shalin-dev

Copy link
Copy Markdown
Author

Thanks for the thorough review @kommander — all feedback addressed in this push.

Changes:

  1. Replaced childExists memo with sessionMissing signal — The old memo checked sync.data.session (stale cache populated by bootstrap/SSE, not by sync outcome). The new signal tracks the actual sync failure: createSignal(false)setSessionMissing(true) in .catch(). Single source of truth based on what actually happened.

  2. Error is recorded, not swallowed.catch() now sets the signal instead of being a no-op catch(() => {}). The error state propagates to the UI layer.

  3. onClick conditionally passed — When sessionMissing() is true, onClick is undefined. InlineTool already handles this: no hover state, no click affordance, muted text. No more "clickable but does nothing" state.

  4. Removed the synthetic test — Agreed it was testing JavaScript, not our code. No TUI testing infrastructure exists in this codebase, so no test is better than a misleading one.

Net diff: +12 -34 lines
Typecheck: All 14 packages pass clean

…g-child-session

# Conflicts:
#	packages/opencode/src/cli/cmd/tui/routes/session/index.tsx
@shalin-dev

Copy link
Copy Markdown
Author

Resolved merge conflicts with upstream/dev. The fix now incorporates the new retry error dialog feature:

  • sessionMissing signal tracks actual sync failure (not stale cache)
  • onClick is conditionally passed (no affordance when session missing)
  • Preserved the retry error dialog from upstream
  • Net change: +17 -18 lines

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

TUI crashes when task history references a missing child session

2 participants